/**
 * @file
 * @auth jinguangguo
 * @date 2016/12/29
 */

import Vue from 'vue';
import Validator from '../../../../../grsc-base/component/Validator/main';
import Help from '../../../../../grsc-base/component/Help.vue';
import commonService from '../../../../common/commonService';

import CreatSell from './CreateSell.vue';
import CreatBuy from './CreateBuy.vue';

import tpl from './tpl.html';
import config from '../../config';


// const AD_TYPE_SELL = 'sell';
// const AD_TYPE_BUY = 'buy';
//
// const DO_TYPE_CREATE = 'create';
// const DO_TYPE_UPDATE = 'update';

export default Vue.extend({
    name: 'AdCreate',
    template: tpl,
    components: {
        Validator,
        CreatSell,
        CreatBuy,
        Help
    },
    data(){
        let doType = config.DO_TYPE_CREATE;
        if (this.$route.fullPath.indexOf('update') >= 0) {
            doType = config.DO_TYPE_UPDATE;
        }
        return {
            type: this.$route.params.type || config.AD_TYPE_SELL,  // sell / buy
            config: config,
            doType: doType,
            level: 'LEVEL0',
            nickName: ''
        }
    },
    created() {
        commonService.basic().done((rep) => {
            this.isLoading = false;
            if (rep.code === window.CODE.SUCCESS) {
                let user = rep.data;
                this.level = user.authLevel;
                this.nickName = user.nickname;
            }
        });
    },
    mounted(){


    },
    methods: {
        setType(type) {
            this.type = type;
            // this.$router.replace({
            //     name: 'adCreate',
            //     params: {
            //         type: type
            //     }
            // });

        }
    }
});
